/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package jardinevolutivo;

import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import javax.swing.BorderFactory;
import javax.swing.BoxLayout;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JRadioButton;

/**
 *
 * @author Luis Roberto
 */
public class Ventana extends JFrame{
    
    private Jardin jardin;
    public static int[] PREFERENCIAS = { 38, 205, 1 };
    private ButtonGroup tamsflor;
    private JRadioButton florGrande, florMediana, florPequena;
    private ButtonGroup tamsTallo;
    private JRadioButton talloGrande, talloMediana, talloPequena;
    private ButtonGroup colores;
    private JRadioButton rojo, amarillo, azul;
    private JButton evolucion;
    
    public Ventana() throws Exception{
        setTitle("JARDIN EVOLUTIVO");
        setLayout(new BorderLayout());
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        
        jardin = new Jardin();
        add(jardin, BorderLayout.CENTER);
        
        JPanel panelFlor = new JPanel();
        panelFlor.setBorder(BorderFactory.createTitledBorder("FLOR"));
        panelFlor.setLayout(new BoxLayout(panelFlor, BoxLayout.Y_AXIS));
        tamsflor = new ButtonGroup();
        florGrande = new JRadioButton("Grande");
        florGrande.addItemListener(manejador);
        florMediana = new JRadioButton("Mediana");
        florMediana.setSelected(true);
        florMediana.addItemListener(manejador);
        florPequena = new JRadioButton("Pequena");
        florPequena.addItemListener(manejador);
        tamsflor.add(florGrande);
        tamsflor.add(florMediana);
        tamsflor.add(florPequena);
        panelFlor.add(florGrande);
        panelFlor.add(florMediana);
        panelFlor.add(florPequena);
        
        JPanel panelTallo = new JPanel();
        panelTallo.setBorder(BorderFactory.createTitledBorder("TALLO"));
        panelTallo.setLayout(new BoxLayout(panelTallo, BoxLayout.Y_AXIS));
        tamsTallo = new ButtonGroup();
        talloGrande = new JRadioButton("Grande");
        talloGrande.addItemListener(manejador);
        talloMediana = new JRadioButton("Mediano");
        talloMediana.setSelected(true);
        talloMediana.addItemListener(manejador);
        talloPequena = new JRadioButton("Pequeno");
        talloPequena.addItemListener(manejador);
        tamsTallo.add(talloGrande);
        tamsTallo.add(talloMediana);
        tamsTallo.add(talloPequena);
        panelTallo.add(talloGrande);
        panelTallo.add(talloMediana);
        panelTallo.add(talloPequena);
        
        JPanel panelColor = new JPanel();
        panelColor.setBorder(BorderFactory.createTitledBorder("Color"));
        panelColor.setLayout(new BoxLayout(panelColor, BoxLayout.Y_AXIS));
        colores = new ButtonGroup();
        rojo = new JRadioButton("Rojo");
        rojo.setSelected(true);
        rojo.addItemListener(manejador);
        amarillo = new JRadioButton("Amarillo");
        amarillo.addItemListener(manejador);
        azul = new JRadioButton("Azul");
        azul.addItemListener(manejador);
        colores.add(rojo);
        colores.add(amarillo);
        colores.add(azul);
        panelColor.add(rojo);
        panelColor.add(amarillo);
        panelColor.add(azul);
        
        evolucion = new JButton("EVOLUCIONAR");
        evolucion.addActionListener(accionBoton);
        
        JPanel panelGeneral = new JPanel();
        panelGeneral.setBorder(BorderFactory.createTitledBorder("PREFERENCIAS"));
        panelGeneral.setLayout(new BoxLayout(panelGeneral, BoxLayout.X_AXIS));
        panelGeneral.add(panelFlor);
        panelGeneral.add(panelTallo);
        panelGeneral.add(panelColor);
        panelGeneral.add(evolucion);
        
        add(panelGeneral, BorderLayout.NORTH);
        pack();
        setVisible(true);
    }
    
    private ItemListener manejador = new ItemListener() {

        @Override
        public void itemStateChanged(ItemEvent e) {
            if(florGrande.isSelected())
                PREFERENCIAS[Flor.TAM_FLOR] = 66;
            if(florMediana.isSelected())
                PREFERENCIAS[Flor.TAM_FLOR] = 38;
            if(florPequena.isSelected())
                PREFERENCIAS[Flor.TAM_FLOR] = 18;
            
            if(talloGrande.isSelected())
                PREFERENCIAS[Flor.TAM_TALLO] = 270;
            if(talloMediana.isSelected())
                PREFERENCIAS[Flor.TAM_TALLO] = 205;
            if(talloPequena.isSelected())
                PREFERENCIAS[Flor.TAM_TALLO] = 135;
            
            if(rojo.isSelected())
                PREFERENCIAS[Flor.COLOR_FLOR] = 0;
            if(amarillo.isSelected())
                PREFERENCIAS[Flor.COLOR_FLOR] = 1;
            if(azul.isSelected())
                PREFERENCIAS[Flor.COLOR_FLOR] = 2;

        }
    };
    
    private ActionListener accionBoton = new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            jardin.evolucionar();
        }
    };
}
